package com.alien.admin.modules.gitlab.service.utils;

import com.alien.admin.modules.system.domain.DictDetail;
import com.alien.admin.modules.system.repository.DictDetailRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

@Component
public class EnvUtils {

    @Autowired
    private DictDetailRepository dictDetailRepository;
    private final String mergeBranchDictName = "branch";


    public List<String> getMergeBranchList() {
        List<DictDetail> dictDetails = dictDetailRepository.findByDictName(mergeBranchDictName);
        return dictDetails.stream().map(dictDetail -> dictDetail.getValue()).collect(Collectors.toList());
    }

    public String getEnvStandardBranch(String env) {
        List<DictDetail> dictDetails = dictDetailRepository.findByDictName(mergeBranchDictName);
        DictDetail envDict = dictDetails.stream()
                .filter(dictDetail -> dictDetail.getValue().contains(env)).findFirst().get();
        return envDict.getValue();
    }
}
